home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr08 / dbdesign.zip / DBDESIGN.TXT
Text File  |  1993-06-01  |  19KB  |  403 lines

  1.             Database Design and Implementation Basics
  2.  
  3. This document describes why and how to use Alpha Four. It is
  4. intended for people who are relatively new to database design.
  5. The document will explain uses of Alpha Four, show a step-by-step
  6. outline of how to implement the program, and provide a
  7. description of the necessary terms and concepts.
  8.  
  9. Alpha Four, The Relational Database for Non-programmers, is a
  10. tool used to store, process, and provide information quickly and
  11. easily. Data may be imported from other programs, such as
  12. spreadsheets, word processors, and other database programs. It
  13. can also be typed in with the option of using powerful "field
  14. rules" to help speed data entry and prevent mistakes. Once
  15. stored, information may easily be searched, sorted, filtered,
  16. changed, ordered, and otherwise manipulated. Lastly, data may be
  17. provided or "output" as letters, reports, mail labels, and other
  18. forms.
  19.  
  20. Before you start to put your data into Alpha Four, a structure
  21. (or structures) must first be created called a database.  The
  22. better you design your databases, the easier it will be to input,
  23. process, and output your data.
  24.  
  25.  
  26.                 Explanation of Terms and Concepts
  27.  
  28. A database is a structure which holds certain types of
  29. information about people or things. An example of a manual
  30. database is a checkbook register.
  31.  
  32. Number Date        Description        T     Deposit Withdrawal
  33. ______ ________ ___________________   ___ _______ __________
  34. 1001   2/1/93   Country Club                         600.00
  35.                 Apartments
  36. 1002   2/7/93   Fry's Food and Drug                   52.87
  37. 1003   2/9/93   Sonoran Desert Museum   X             50.00
  38. 001    2/15/93  Pay check deposit         1500.00          
  39. (T means tax deductible)
  40.                                 
  41. In this database, there are four records and six fields.  Each
  42. row (transaction) is considered a RECORD, and each column --or
  43. unit of information-- is considered a FIELD. The fields in this
  44. example are:  Number, Date, Description, Tax Deductible,
  45. Deposit, and Withdrawal.
  46.  
  47. In database terminology, we would say that each field can be
  48. classified in two ways. The first classification is by its data
  49. type. The second is by whether it is a key field. We'll talk more
  50. about key fields later.  For now, we will discuss data types
  51.  
  52. A data type refers to the kind of information a field can hold.
  53. Alpha Four  has five different data types:
  54.  
  55. Field Type...Description
  56. Character....Contains up to 254
  57.              alphanumeric characters
  58. Date.........Contains dates
  59. Numeric......Holds numbers
  60. Logical......Holds a true or false value
  61. Memo.........Holds up to 5,000 characters
  62.              of text
  63.  
  64. Looking back at our check book database, let's see how each of
  65. the fields can be classified. The field Date is a date field;
  66. Deposit and Withdrawals are both numeric. Tax deductible is a
  67. logical field (It can either be deducted or it can't.).
  68. Description is a Character field since it will hold  alphanumeric
  69. information and will be less than 254 characters long. The
  70. transaction number field will also be a character field.
  71.  
  72. You may be wondering why we classified transaction number as a
  73. character  field. We did this because, even though it holds a
  74. number, we will not be performing mathematical operations on that
  75. number. Unlike the deposit and withdrawal fields which we may
  76. eventually wanted to add and subtract, we will never add or
  77. subtract transaction numbers. Technically we could have made
  78. Transaction Number a numeric field, but it is good idea to make
  79. number fields character fields if you will not be performing math
  80. on them.
  81.  
  82. OK, now that we have talked about data types, let's discuss key
  83. fields.  A key field is the pivotal field.  A key is the field or
  84. fields which identify the record. It is the field(s) which all of
  85. the other fields describe. In our checkbook database, the
  86. Transaction Number would be the key field. Every database must
  87. have a key, but the key doesn't have to be just one field. Let's
  88. say we had a database in which we recorded the daily sales for
  89. each of  our salespeople.
  90.  
  91.         Initials of      
  92. Date    Salesperson      Sales
  93. _______ ______________ _______
  94. 2/1/93  S.C.           3000.00
  95. 2/1/93  N.K.           -800.00
  96. 2/1/93  R.S.           1678.00
  97. 2/2/93  S.C.            258.00
  98. 2/2/93  N.K.           7800.00
  99. 2/2/93  R.S.          12562.00
  100. 2/3/93  S.C.            322.00
  101. 2/3/93  N.K.           22000.0
  102. 2/3/39  R.S.           1250.00
  103.  
  104. In this example the key would be the Date field and the Initials
  105. field, since you need to know both units of information to find
  106. out sales.
  107.  
  108. In the previous example, we just looked at one database, a
  109. checkbook register. Most of the time, more than one database will
  110. be necessary. Different databases should be used to hold
  111. different types of information about people or things.  Below are
  112. examples of some typical databases:
  113.  
  114. Doctor's Office     Retailer     School Admin     Library
  115. ___________________ ____________ ________________ _________
  116. Patients            Customers    Students         Members
  117. Prescriptions       Inventory    Classes          Books
  118. Patient Accounts    Invoices     Teachers         Donations
  119.  
  120. Note how each database describes a different type of person or
  121. thing. Think about what types of information you need for your
  122. own use. On a piece of paper, write the heading "Databases," and
  123. list the different types of people and things you wish to store.
  124.  
  125. Let's review what we've learned so far. We have defined a
  126. database. We know each database is made of multiple records, and
  127. that each record contains multiple fields. We also discussed how
  128. fields are classified by data types as well as what the different
  129. data types are for Alpha Four. Lastly, we said that most uses of
  130. Alpha Four require multiple databases, and that each database is
  131. a collection of specific kinds of information on people or
  132. things.
  133.  
  134. OK,  now let's divide the databases we wrote down into individual
  135. fields. Example:
  136.  
  137.                          Databases (retailer)
  138. Customers
  139.    CUSTOMER_#, NAME, ADDRESS, PHONE_#
  140.  
  141. Invoices
  142.    INVOICE_#, DATE, CUSTOMER_#, SHIPPING ADDRESS, PHONE_#, ITEMS
  143. PURCHASED
  144.  
  145. Inventory
  146.    STOCK_#, DESCRIPTION, COST, RETAIL, QTY_IN_STOCK
  147.  
  148. After completing this exercise, you would have all the databases
  149. and fields you would need to get started.  However, further
  150. planning at this stage can make your database more intelligible,
  151. and that can save you a lot of time in the long run.
  152.  
  153. The process of refining a database's design is called
  154. "normalization."  To help explain how to normalize databases,
  155. let's look back to the example of the retailer. Specifically,
  156. let's look at the invoices database.
  157.  
  158. This is the structure of the Invoices database before
  159. normalization:
  160.  
  161.  Field  Field Description
  162.  _____  _________________
  163.  1.     INVOICE_#
  164.  2.     DATE
  165.  3.     CUSTOMER_#
  166.  4.     SHIP_ADDR
  167.  5.     PHONE_#
  168.  6.     ITEMS_PUR
  169.  
  170. The first step will be to break down the fields into smaller
  171. fields, where appropriate. First, let's look at the SHIP_ADDR
  172. field.  The type of  information we would store in this field
  173. would be the shipping street address, city, state, and zip code.
  174. By breaking down the SHIP_ADDR field into four smaller fields
  175. (i.e. STREET, CITY, STATE, ZIP), we will be given more
  176. flexibility. One of the advantages of making this separation is
  177. that it would be easier to search or order information by city,
  178. state, and/or zip code; this is especially useful for tracking
  179. shipments or utilizing mailing lists.
  180.  
  181. Next, let's look at the field PHONE_#. We could also break this
  182. field down into two smaller fields, area code and seven digit
  183. phone number. However, because it is unlikely that we would ever
  184. want to search or order our information by area codes or seven
  185. digit phone numbers, it is best that we leave it as one field.
  186.  
  187. The most tricky of the Invoice database's fields is the ITEMS_PUR
  188. field. With our current structure, this field could hold the
  189. stock numbers, descriptions, prices, and quantities for items
  190. being sold. To normalize this field, we would first want to break
  191. the information down into separate fields. We would end up with:
  192. STOCK#'s, DESC's, QTY's, and PRICEs. The problem we have now is
  193. that each field could still need to hold information of multiple
  194. items, unless we limited each invoice to record the sale of only
  195. one kind of item. If we look back the definition of a field (see
  196. glossary), we will see that a field is only supposed to hold ONE
  197. unit of information.
  198.  
  199. To solve this problem, we have two options. The first is to
  200. create multiple fields for the number of items we could
  201. conceivably sell on one invoice. For example, we could have
  202. STOCK_#1, DESC_1, STOCK_#2, DESC_2, etc. This method is
  203. appropriate in some situations, however, it can be limiting for
  204. several reasons. First, each invoice can only have as many items
  205. as there are fields; second, it will take more storage space in
  206. your computer than the alternate method; third, it takes longer
  207. to set up and change field rules (discussed later); lastly, it
  208. takes more effort to search for data later on.
  209.  
  210. The alternate, and generally preferred method, breaks the
  211. ITEMS_PUR field into another separate database, called the
  212. Line_Items database. The Line_Items database has the invoice
  213. number as the key field and as a linking field.
  214.  
  215. Invoices Database                   Line_items Database
  216. INVOICE_#     ---common-field--->   INVOICE_#
  217. DATE                                STOCK_#
  218. CUSTOMER_#                          DESC
  219. SHIP_ADDR                           QTY
  220. PHONE_#                             PRICE
  221.  
  222. Each record in the Line_Items database would represent one line
  223. of an invoice. This way the number of lines you could put on one
  224. invoice would be virtually unlimited, since you can keep entering
  225. more records into the Line_Items database.  By breaking a field
  226. down into an entirely new database, we are creating a SET.
  227. Databases are linked together into SETs by common fields through
  228. the use of linking indexes. In this case, the common field
  229. between the Invoice and Line_Items databases is INVOICE_#. The
  230. linking index would contain INVOICE_# as the key field.
  231.  
  232. The creation and use of SETs is an important and powerful tool.
  233. For more information, look at the reference manual and tutorial
  234. under the heading "Sets." Also, you may wish to request our
  235. document called "Invoicing Sets." This document may be requested
  236. by phone, fax, mail, or it may be downloaded from our BBS.
  237.  
  238.  
  239.                 An Important Note About Using Sets
  240.  
  241. In this example, the link between the Invoice and Line_Items
  242. database is a one to many link (1:n).  In other words, for each
  243. (one) INVOICE_# in the Invoice database, there could be multiple
  244. (many) records in the Line_Items database with a matching
  245. INVOICE_#.  As a general rule, no database should have more than
  246. one 1:n  link.  If you're database design does, we strongly
  247. advise changing it. Unless you are very familiar with database
  248. theory, this type of situation  can produce unpredictable
  249. results.
  250.                                 
  251.                              Indexes
  252.  
  253. In the above example, we mentioned the term "linking index."
  254. Without getting too technical, this is a brief description of
  255. what an index is:  An indexes is a file which contains the
  256. records number and parts of data (called "keys") for each of the
  257. records in a database.  The more common uses of indexes are
  258. ordering data, connecting databases in a set, performing lookups,
  259. eliminating duplicate entries during data entry, and finding
  260. records.  If, for example, you had a database of customers, and
  261. you wanted to find the first record for a given customer, you
  262. would use an index based on the customer field.   See the
  263. reference manual and tutorial for more information on indexes.
  264.  
  265. As mentioned above, one time indexes are needed is when
  266. performing a lookup. A lookup is a type of field rule.  Field
  267. rules are guidelines you set up that the data must conform to
  268. and/or steps to automate data entry. Field rules only apply when
  269. the data is entered or changed; they do not apply to data which
  270. have already been entered. A common field rule is "Case
  271. Conversion." You can set up case conversion to automatically
  272. capitalize, for example, the two letter state abbreviations as
  273. they are being entered. One of the most powerful field rules is a
  274. lookup. A lookup can check databases for the presence or absence
  275. of information, and can fill in other fields based on what it
  276. finds. For example, it can be used to fill in the city and state
  277. fields when a zip code is entered. It also check to make sure
  278. duplicate information is not being entered.  Below is more
  279. information on field rules.
  280.  
  281.                            Field Rules
  282.  
  283. If people were perfect, there would probably be no need for field
  284. rules.  The purpose of field rules is to make data entry faster
  285. and more accurate. You don't have to have field on your database,
  286. but they can be quite helpful. Below is a list of the most
  287. commonly used field rules.  Many of these rules are discussed in
  288. the tutorial, and all of them are in the reference manual.  This
  289. list is meant to provide an overview and for quick reference.
  290.  
  291.     Field Rule                      Description
  292. Calculated............Similar to a default, except the value can
  293.                       not be changed by the user, and the
  294.                       expression will calculate every time the
  295.                       record is updated, not just the first time
  296.                       it is entered.
  297. Case Convert..........Automatically converts words to uppercase,
  298.                       lowercase, or all capital letters.
  299. Default...............A value or calculation which fills in the
  300.                       first time a record is entered. The user can
  301.                       go back and change it if necessary. If you
  302.                       have an invoice screen, and you usually sell
  303.                       only to customers in one state, you can make
  304.                       the state field default to that state.
  305. Increment.............This sequentially numbers records as they
  306.                       are entered.
  307. Lookup................Checks a table or database for the presence
  308.                       (or absence) of information, allows display
  309.                       of this information in a pop-up window and
  310.                       can fill in fields based on this
  311.                       information. This is probably the most
  312.                       powerful of field rules.
  313. Mask..................Allows only certain kinds of information to
  314.                       be entered. It can, for instance, make sure
  315.                       only numbers are entered into a phone number
  316.                       field.
  317. Required..............Will not allow the user to save the record
  318.                       until this field is filled in.
  319. Skip Expression.......Skips over a field during data entry if
  320.                       specified conditions are met.
  321. Template..............Sets up fixed, non-editable characters in a
  322.                       field. For example. a social security number
  323.                       field always has a dash (-) after the first
  324.                       three numbers and the second three numbers.
  325. Validation Expression.Assures that correct data is entered based
  326.                       on a formula. For example, a date of birth
  327.                       field must have a date before today's date.
  328.  
  329. Once the field rules are in place, you are ready to create your
  330. forms, browse tables, reports, letters, and/or mail labels. You
  331. can also automate and simplify the use of Alpha Four for yourself
  332. or your end users by the use of applications and scripts.
  333.  
  334.                     Applications and Scripts
  335.  
  336. Scripts and applications are means of automating the use of Alpha
  337. Four so that even users who are not familiar with the program can
  338. easily use it.  Scripts are similar to small programs which can
  339. automatically perform operations in Alpha Four, make decisions,
  340. and prompt users for input.  An application is a menu structure
  341. which can be set up to perform Alpha Four operations, play (or
  342. use) scripts, and provide enhanced security to your data.  If you
  343. are designing an application for others to use, chances are you
  344. will want to create an application. Consult the reference manual
  345. and tutorial for more information.  Also, Alpha Software's BBS is
  346. a good source for sample scripts and applications written by
  347. other Alpha Four users.
  348.  
  349.  
  350.                             Glossary
  351.  
  352. 1:1...............A relationship in a SET where one record in
  353.                   one database  matches one other record in
  354.                   another database. This is  often referred to
  355.                   as a "one to one link."
  356. 1:n...............A relationship in a SET where one record in
  357.                   one database  matches one OR MORE records in
  358.                   another database. This is often referred  to
  359.                   as a "one to many link."
  360. Database..........A collection of records, sometimes called a
  361.                   table.
  362. Field.............A unit of information contained within a
  363.                   record.
  364. Field Data Types..The kind of data which can be stored in a
  365.                   particular field. Alpha Four has five
  366.                   different data types:  Numeric, Logical, Memo,
  367.                   Date, and Character.
  368. Index.............A file which stores the order of records in
  369.                   the database (based on an index expression).
  370.                   For example, an index may sort records by last
  371.                   name.
  372. Key Linking Field.One or more fields that identify the record.
  373.                   A field (unit if information) which is common
  374.                   between  two or more other records in the same
  375.                   or a different database.
  376. Normalization.....A process of breaking down databases into
  377.                   their simplest form.
  378. Record............A collection of fields. There are multiple
  379.                   records in a  database.
  380. Set...............Two or more databases linked by one or more
  381.                   common fields. A set works much like one large
  382.                   database.
  383.                                 
  384.                      Implementation Outline
  385.  
  386. 1.  Make a separate database for each set of related attributes,
  387.     and give each database a primary key.
  388. 2.  Normalize your databases.
  389.     a.  Divide fields into component parts when necessary.
  390.     b.  Divide repeating groups of fields into separate databases
  391.         when necessary.
  392.         (I.e. build Sets)
  393.     c.  Make sure no database has more than one 1:n link.
  394. 3.  Decide on data types for each field.
  395. 4.  Enter the databases, linking indexes, and sets into Alpha
  396.     Four.
  397. 5.  Decide on and set up field rules (optional).
  398. 6.  Set up forms, reports, browse tables, letters, mail labels,
  399.     and/or indexes (optional).
  400. 7.  Set up scripts and applications to automate and simplify use
  401.     of the program (optional).
  402.  
  403.